/**
 * small-spring
 *
 * @author yuanchen
 * @date 2021-06-29 16:20
 */
package cn.bugstack.springframework.beans.factory.support;


import cn.bugstack.springframework.beans.factory.config.BeanDefinition;
import cn.bugstack.springframework.exception.BeansException;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author yuanchen
 * @date 2021-06-29 16:20
 */
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {

    private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();


    @Override
    protected BeanDefinition getBeanDefinition(String beanName) {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if (beanDefinition == null){
            throw new BeansException("No bean named '" + beanName + "' is defined");
        }
        return beanDefinition;
    }

    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }
}
